<template>
	<view class="content">
		<image class="top-banner"
			src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/raffle_bg.png"></image>
		<view class="info-block">
			<image :src="cloudStorage + '/file/K4X5DIY7.png'" class="logo"></image>
			<template v-if="infoList.length>0">
				<view class="account-block">
					<view class="tips">请选择一个账号登录</view>
					<view @click="chooseLogin(item)" class="account-item" v-for="item in infoList">
						<image class="user-avatar" :src="cloudStorage+item.faceUrl"></image>
						<view class="user-info">
							<view class="name">{{item.name}}</view>
							<view class="mobile">{{item.phone.substr(0,3)+'****'+item.phone.substr(7,4)}}</view>
						</view>
						<view class="arrow iconfont icon-gengduo"></view>
					</view>
				</view>
			</template>
			<!-- <view class="btn-block">
				<button class="entrance-btn" hover-class="none" open-type="getPhoneNumber"
					@getphonenumber="getPhoneNumber">微信用户一键登录</button>
			</view> -->
		</view>
	</view>
</template>

<script>
	import {
		getWxLoginCode
	} from '@/util/user.js';
	import {
		weChatLogin,
		savePhoneNumberByCode,
		selectAccount
	} from '@/api/user.js';
	import {
		getStorage,
		setStorage
	} from '@/util/auth';
	export default {
		data() {
			return {
				inviteCode: '',
				infoList: []
			};
		},
		onLoad() {
			const userInfo = getStorage('user');
			if (getStorage('scene')) {
				this.inviteCode = getStorage('scene');
			}
			if (userInfo) {
				uni.redirectTo({
					url: '/pages/index/index'
				});
			}
			if (!this.$store.getters.token) {
				getWxLoginCode().then((code) => {
					uni.showLoading({
						title: '加载中',
						mask: true,
					})
					this.$store.dispatch('user/login', code).then(res => {
						if (res && res.length > 1) {
							this.infoList = res;
						} else {
							uni.redirectTo({
								url: '/pages/index/index'
							});
						}
					})
				})
			}
		},
		methods: {
			chooseLogin(user) {
				uni.showLoading({
					title: '登录中',
					mask: true
				})
				selectAccount({
					userid: user.id
				}).then(res => {
					this.$store.commit('user/SET_TOKEN', res.token);
					this.$store.commit('user/SET_USER', user);
					uni.redirectTo({
						url: '/pages/index/index'
					});
				})
			},
		}
	};
</script>

<style lang="scss" scoped>
	.content {
		width: 100vm;
		height: 100vh;

		.top-banner {
			width: 100%;
			height: 100%;
			position: absolute;
		}

		.info-block {
			position: relative;
			display: flex;
			flex-direction: column;
			align-items: center;

			.logo {
				width: 200rpx;
				height: 200rpx;
				margin-top: 36%;
			}

			.account-block {
				// position: absolute;
				// transform: translate(-50%, -50%);
				// left: 50%;
				// top: 45%;
				width: 600rpx;
				padding: 0 30rpx;
				border-radius: 5px;
				background: #fff;
				box-shadow: 0 0 6px 0px #dadada;
				margin-top: 120rpx;

				.tips {
					font-size: 28rpx;
					color: #999;
					margin-top: 30rpx;
					margin-bottom: 20rpx;
				}

				.account-item:last-child {
					margin-bottom: 0;
					border-top: none;
					border-bottom: none;
				}

				.account-item {
					padding: 20rpx 0;
					width: 100%;
					height: 120rpx;
					border-radius: 2px;
					display: flex;
					border-bottom: 1px solid #efefef;
					border-top: 1px solid #efefef;

					.user-avatar {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						margin-right: 20rpx;
						border: none;
					}

					.user-info {
						flex-grow: 1;
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.mobile {
							color: #ccc;
							font-size: 24rpx;
						}

						.name {
							font-size: 28rpx;
						}
					}

					.arrow {
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #ccc;
					}
				}
			}

			.btn-block {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-top: 74%;

				.entrance-btn {
					width: 480rpx;
					height: 90rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					// background: #fff;
					// color: #1a1a1a;
					background: linear-gradient(270deg, #FFC43F 0%, #FDD401 100%);
					color: #FF2F34;
					font-weight: bold;
					font-size: 28rpx;
					border-radius: 60rpx;
				}

				.entrance-btn1 {
					width: 480rpx;
					height: 90rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background: #fff;
					font-size: 28rpx;
					border-radius: 60rpx;
					margin-top: 40rpx;
				}
			}
		}
	}
</style>